/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.demo.wzq.myapplication;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Color;

import com.yalantis.ucrop.UCrop;
import com.yalantis.ucrop.UCropActivity;

import java.io.File;

/**
 * 创建时间：2017/12/7
 * 作者：kb_jay
 * 功能描述：
 */

public class CustomUcropConfig {
    /**
    *@date  2017/12/8
    *@author  kb_jay
    *@Desctiption  用于配置截图上传答案的ucrop
    */
    public static UCrop getAnswerUcropConfig(Context context, UCrop uCrop, File sourceFile) {
        UCrop.Options options = new UCrop.Options();
        options.setHideBottomControls(false);
        options.setAllowedGestures(UCropActivity.SCALE, UCropActivity.ROTATE, UCropActivity.NONE);
        options.setIsAnswerCrop(true);
        options.setCropFrameStrokeWidth(
                context.getResources().getDimensionPixelOffset(R.dimen.ucrop_crop_frame_width));
        options.setCropGridStrokeWidth(
                context.getResources().getDimensionPixelOffset(R.dimen.ucrop_crop_grid_width));
        options.setCropGridColumnCount(2);
        options.setCropGridRowCount(2);
        options.setShowCropFrame(true);
        options.setActiveWidgetColor(Color.WHITE);
        BitmapFactory.Options btOption = new BitmapFactory.Options();
        btOption.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(sourceFile.getAbsolutePath(), btOption);
        float ratio = (float) btOption.outWidth / (float) btOption.outHeight;
        options.setSourceAspectRetio(ratio);

        uCrop.withOptions(options);
        uCrop.withAspectRatio(1f, 0.5f);
        return uCrop;
    }

    /**
    *@date  2017/12/8
    *@author  kb_jay
    *@Desctiption  用于配置截取头像的ucrop
    */
    public static UCrop getIconUcropConfig(Context context, UCrop uCrop){
        UCrop.Options options = new UCrop.Options();
        options.setHideBottomControls(true);
        options.setAllowedGestures(UCropActivity.SCALE,UCropActivity.NONE,UCropActivity.NONE);
        options.setCircleDimmedLayer(true);
        options.setShowCropFrame(false);
        options.setShowCropGrid(false);
        uCrop.withOptions(options);
        uCrop.withAspectRatio(1,0.5f);
        return uCrop;
    }

}
